package com.arraymasterx.controller;

import com.arraymasterx.model.request.MatrixRequest;
import com.arraymasterx.model.response.DeterminantResponse;
import com.arraymasterx.model.response.MatrixResponse;
import com.arraymasterx.service.MatrixService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/matrix")
@Tag(name = "Matrix Operations", description = "Operations related to matrix calculations")
public class MatrixController {

    private final MatrixService matrixService;

    @Autowired
    public MatrixController(MatrixService matrixService) {
        this.matrixService = matrixService;
    }

    @PostMapping("/multiply")
    @Operation(summary = "Multiply two matrices", responses = {
            @ApiResponse(responseCode = "200", description = "Successful operation", content = @Content(schema = @Schema(implementation = MatrixResponse.class))),
            @ApiResponse(responseCode = "400", description = "Invalid input") })
    public ResponseEntity<MatrixResponse> multiplyMatrices(@RequestBody MatrixRequest request) {
        MatrixResponse response = matrixService.multiplyMatrices(request);
        return ResponseEntity.ok(response);
    }

    @PostMapping("/determinant")
    @Operation(summary = "Calculate the determinant of a square matrix", responses = {
            @ApiResponse(responseCode = "200", description = "Successful operation", content = @Content(schema = @Schema(implementation = DeterminantResponse.class))),
            @ApiResponse(responseCode = "400", description = "Invalid input") })
    public ResponseEntity<DeterminantResponse> determinant(@RequestBody MatrixRequest request) {
        DeterminantResponse response = matrixService.matrixDeterminant(request);
        return ResponseEntity.ok(response);
    }
}